package xworker.gluon.glisten.control;

import com.gluonhq.charm.glisten.control.TimePicker;
import org.xmeta.ActionContext;
import org.xmeta.Thing;
import xworker.javafx.beans.property.PropertyFactory;
import xworker.javafx.util.JavaFXUtils;

import java.time.LocalTime;

public class TimePickerActions {
    static{
        PropertyFactory.regist(TimePicker.class, "timeProperty", o -> {
            TimePicker obj = (TimePicker) o;
            return obj.timeProperty();
        });
    }

    public static void init(TimePicker node, Thing thing, ActionContext actionContext) {
        DialogActions.init(node, thing, actionContext);

        LocalTime time = JavaFXUtils.getObject(thing, "time", actionContext);
        if (time != null) {
            node.setTime(time);
        }

    }

    public static TimePicker create(ActionContext actionContext) {
        Thing self = actionContext.getObject("self");
        TimePicker node = new TimePicker();
        init(node, self, actionContext);

        actionContext.peek().put("parent", node);
        for (Thing child : self.getChilds()) {
            child.doAction("create", actionContext);
        }

        actionContext.g().put(self.getMetadata().getName(), node);
        return node;
    }
}